<template>
<div>
  <el-dialog
    :title="title"
    :close-on-click-modal="false"
     v-dialogDrag
    :visible.sync="visible">
    <el-form :model="inputForm" size="small" ref="inputForm" v-loading="loading" :class="method==='view'?'readonly':''"  :disabled="method==='view'"
             label-width="120px">
      <el-row  :gutter="15">
        
        <el-col :span="12">
            <el-form-item label="部门" prop="department.id"
                :rules="[
                  {required: true, message:'部门不能为空', trigger:'blur'}
                 ]">
          <SelectTree
                      ref="department"
                      :props="{
                          value: 'id',             // ID字段名
                          label: 'name',         // 显示名称
                          children: 'children'    // 子级字段名
                        }"

                      url="/dlyrl/hr/orporateinstitutions/orporateInstitutions/treeData"
                      :value="inputForm.department.id"
                      :clearable="true"
                      :accordion="true"
                      @getValue="(value) => {inputForm.department.id=value}"/>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="岗位" prop="job"
                :rules="[
                  {required: true, message:'岗位不能为空', trigger:'blur'}
                 ]">
              <el-input v-model="inputForm.job" placeholder="请填写岗位"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="缴费日期" prop="paytime"
                :rules="[
                  {required: true, message:'缴费日期不能为空', trigger:'blur'}
                 ]">
                <el-date-picker
                      style="width: 100%;"
                      v-model="inputForm.paytime"
                      type="datetime"
                      value-format="yyyy-MM-dd HH:mm:ss"
                      placeholder="选择日期时间">
                    </el-date-picker>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="个人账户" prop="individualAccount"
                :rules="[
                  {required: true, message:'个人账户不能为空', trigger:'blur'}
                 ]">
              <el-input v-model="inputForm.individualAccount" placeholder="请填写个人账户"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="账户状态" prop="accountStatus"
                :rules="[
                  {required: true, message:'账户状态不能为空', trigger:'blur'}
                 ]">
                <el-select v-model="inputForm.accountStatus" placeholder="请选择"  style="width: 100%;">
                          <el-option
                            v-for="item in $dictUtils.getDictList('account_status')"
                            :key="item.value"
                            :label="item.label"
                            :value="item.value">
                          </el-option>
                      </el-select>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="手机号码" prop="phone"
                :rules="[
                  {required: true, message:'手机号码不能为空', trigger:'blur'}
                 ]">
              <el-input v-model="inputForm.phone" placeholder="请填写手机号码"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="单位名称" prop="companyName.id"
                :rules="[
                  {required: true, message:'单位名称不能为空', trigger:'blur'}
                 ]">
          <GridSelect
            title="选择单位名称"
            labelName = 'companyName'
            labelValue = 'id'
            :value = "inputForm.companyName.id"
            :limit="1"
            @getValue='(value) => {inputForm.companyName.id=value}'
            :columns="[
            {
              prop: 'id',
              label: '主键'
            },
            {
              prop: 'companyName',
              label: '企业名称'
            }
            ]"
            :searchs="[
            {
              prop: 'id',
              label: '主键'
            },
            {
              prop: 'companyName',
              label: '企业名称'
            }
            ]"
            dataListUrl="/dlyrl/hr/enterpriseinformation/enterpriseInformation/list"
            entityBeanName="enterpriseInformation"
            queryEntityUrl="/dlyrl/hr/enterpriseinformation/enterpriseInformation/queryById">
          </GridSelect>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="缴存基数" prop="depositBase"
                :rules="[
                  {required: true, message:'缴存基数不能为空', trigger:'blur'}
                 ]">
              <el-input v-model="inputForm.depositBase" placeholder="请填写缴存基数"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="单位缴存比例" prop="companyDepositRatio"
                :rules="[
                  {required: true, message:'单位缴存比例不能为空', trigger:'blur'}
                 ]">
              <el-input v-model="inputForm.companyDepositRatio" placeholder="请填写单位缴存比例"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="单位月缴存额" prop="companyMonthlyDeposit"
                :rules="[
                  {required: true, message:'单位月缴存额不能为空', trigger:'blur'}
                 ]">
              <el-input v-model="inputForm.companyMonthlyDeposit" placeholder="请填写单位月缴存额"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="个人缴存比例" prop="personalDepositRatio"
                :rules="[
                  {required: true, message:'个人缴存比例不能为空', trigger:'blur'}
                 ]">
              <el-input v-model="inputForm.personalDepositRatio" placeholder="请填写个人缴存比例"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="个人月缴存额" prop="personalMonthlyDeposit"
                :rules="[
                  {required: true, message:'个人月缴存额不能为空', trigger:'blur'}
                 ]">
              <el-input v-model="inputForm.personalMonthlyDeposit" placeholder="请填写个人月缴存额"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="账户余额" prop="accountBalance"
                :rules="[
                  {required: true, message:'账户余额不能为空', trigger:'blur'}
                 ]">
              <el-input v-model="inputForm.accountBalance" placeholder="请填写账户余额"     ></el-input>
           </el-form-item>
        </el-col>
        <el-col :span="12">
            <el-form-item label="备注信息" prop="remarks"
                :rules="[
                 ]">
          <el-input type="textarea" v-model="inputForm.remarks" placeholder="请填写备注信息"     ></el-input>
           </el-form-item>
        </el-col>
        </el-row>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button size="small" @click="visible = false">关闭</el-button>
      <el-button size="small" type="primary" v-if="method != 'view'" @click="doSubmit()" v-noMoreClick>确定</el-button>
    </span>
  </el-dialog>
</div>
</template>

<script>
  import SelectTree from '@/components/treeSelect/treeSelect.vue'
  import GridSelect from '@/components/gridSelect'
  export default {
    data () {
      return {
        title: '',
        method: '',
        visible: false,
        loading: false,
        inputForm: {
          id: '',
          remarks: '',
          department: {
            id: ''
          },
          job: '',
          paytime: '',
          individualAccount: '',
          accountStatus: '',
          phone: '',
          companyName: {
            id: ''
          },
          depositBase: '',
          companyDepositRatio: '',
          companyMonthlyDeposit: '',
          personalDepositRatio: '',
          personalMonthlyDeposit: '',
          accountBalance: ''
        }
      }
    },
    components: {
      SelectTree,
      GridSelect
    },
    methods: {
      init (method, id) {
        this.method = method
        this.inputForm.id = id
        if (method === 'add') {
          this.title = `新建公积金表`
        } else if (method === 'edit') {
          this.title = '修改公积金表'
        } else if (method === 'view') {
          this.title = '查看公积金表'
        }
        this.visible = true
        this.loading = false
        this.$nextTick(() => {
          this.$refs.inputForm.resetFields()
          if (method === 'edit' || method === 'view') { // 修改或者查看
            this.loading = true
            this.$http({
              url: `/dlyrl/hr/accumulationfund/accumulationFund/queryById?id=${this.inputForm.id}`,
              method: 'get'
            }).then(({data}) => {
              this.inputForm = this.recover(this.inputForm, data.accumulationFund)
              this.loading = false
            })
          }
        })
      },
      // 表单提交
      doSubmit () {
        this.$refs['inputForm'].validate((valid) => {
          if (valid) {
            this.loading = true
            this.$http({
              url: `/dlyrl/hr/accumulationfund/accumulationFund/save`,
              method: 'post',
              data: this.inputForm
            }).then(({data}) => {
              this.loading = false
              if (data && data.success) {
                this.visible = false
                this.$message.success(data.msg)
                this.$emit('refreshDataList')
              }
            })
          }
        })
      }
    }
  }
</script>